//
//  MyCooperController.m
//  i5db
//
//  Created by iMuse on 15-5-16.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "MyCooperController.h"
#import "MyCooperDetailController.h"
#import "PullTableView.h"
#import "AppCenter.h"
#import "SmallView.h"
#import "CredateHeZuoController.h"

#define cellHeight 70
@interface MyCooperController ()<UITableViewDataSource,UITableViewDelegate,PullTableViewDelegate>
{
    PullTableView * pullTableView;
    NSArray * array ;
}

@end

@implementation MyCooperController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"我的合作";
        array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil];
    }
    return self;
}
-(void)updateViewConstraints
{
    [super updateViewConstraints];
    [pullTableView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view setNeedsUpdateConstraints];
    [self initNavigationBar];
    [self initView];
   
}

-(void) initNavigationBar
{
    [super initNavigationBar];
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 44, 44);
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitle:@"创建" forState:UIControlStateNormal];
    
    /* [button setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal];
     [button setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateSelected];
     */
    
    [button addTarget:self action:@selector(credateCooper:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *temporaryBarButtonItem2 = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    temporaryBarButtonItem2.style = UIBarButtonItemStylePlain;
    
    self.navigationItem.rightBarButtonItem = temporaryBarButtonItem2;
}

-(void)credateCooper:(UIButton*) button
{
    CredateHeZuoController * controller = [[CredateHeZuoController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}



-(void)initView
{
    pullTableView  = [PullTableView newAutoLayoutView];
    [pullTableView setDataSource:self];
    [pullTableView setDelegate:self];
    [pullTableView setPullDelegate:self];
    [pullTableView setRefreshType:PRPullUpLoadMore];
    
    [self.view addSubview:pullTableView];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier = @"i5dbIndefter";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
     tableView.separatorStyle = NO;
    UILabel     * line          = nil;
    UIView      * contentView   = nil;
    UILabel     * titleLabel    = nil;
    UILabel     * companyLabel  = nil;
    SmallView   * iconView      = nil;
    SmallView   * locaView      = nil;
    SmallView   * timeView      = nil;
    if (cell ==nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:identifier] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        line = [UILabel newAutoLayoutView];
        line.backgroundColor = [AppCenter color:@"235,235,241,1"];
        [cell.contentView addSubview:line];
        [line autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
        [line autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
        [line autoSetDimension:ALDimensionHeight toSize:5];
        
        contentView = [UIView newAutoLayoutView];
        [cell.contentView addSubview:contentView];
        [contentView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(5, 0, 5, 0)];
        
        titleLabel = [UILabel newAutoLayoutView];
        titleLabel.text = @"流量置换流量置换流量置换";
        titleLabel.numberOfLines = 0;
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.tag  = 1;
        [contentView addSubview:titleLabel];
        
        [titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
        [titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
      
        companyLabel = [UILabel newAutoLayoutView];
        companyLabel.tag = 2;
        companyLabel.text = @"慧聪-电子汽车网";
        companyLabel.font = [UIFont systemFontOfSize:12];
        companyLabel.textColor = [AppCenter color:@"126,126,126,1"];
        [contentView addSubview:companyLabel];
        [companyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel withOffset:5];
        [companyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
        
        
        
        locaView = [SmallView newAutoLayoutView];
        [locaView settingAttrView:[UIImage imageNamed:@"fujin.png"] text:@"全国" color:[AppCenter color:@"76,187,248,1"]];
        [contentView addSubview:locaView];
        [locaView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [locaView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:3];
        [locaView autoSetDimensionsToSize:CGSizeMake(30, 12)];
        
        
        iconView = [SmallView newAutoLayoutView];
        [iconView settingAttrView:[UIImage imageNamed:@"vipBizIcon102_1.png"] text:@"90" color:[UIColor redColor]];
        [contentView addSubview:iconView];
        [iconView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
        [iconView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:locaView withOffset:5];
        [iconView autoSetDimensionsToSize:CGSizeMake(30, 12)];
        
        timeView = [SmallView newAutoLayoutView];
        timeView.tag = 3;
        [timeView settingAttrView:[UIImage imageNamed:@"mqz_ugc_btn_time.png"] text:@"2014/12/23 17:00:00" color:[AppCenter color:@"126,126,126,1"]];
        [contentView addSubview:timeView];
        [timeView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:companyLabel withOffset:5];
        [timeView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
        [timeView autoSetDimensionsToSize:CGSizeMake(40, 12)];
        
    }else
    {
        titleLabel = (UILabel*)[contentView viewWithTag:1];
        companyLabel = (UILabel*)[contentView viewWithTag:2];
        timeView = (SmallView*)[contentView viewWithTag:3];
    }
    
    //cell.textLabel.text = [array objectAtIndex:[indexPath row]];
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return array.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return cellHeight;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
  
    MyCooperDetailController* controller = [[MyCooperDetailController alloc] init];
    
    [self.navigationController pushViewController:controller animated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:NO];
    [super viewWillAppear:animated];
    
    
}


- (void)viewWillDisappear:(BOOL)animated {
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
